Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OpenFileName) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetParent Lib "user32" (ByVal HwndChild As Long, ByVal hWndNewParent As Long) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type OpenFileName
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Const OFN_READONLY = &H1
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_SHOWHELP = &H10
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
Public Const OFN_EXPLORER = &H80000 ' new look commdlg
Public Function ShowExtendedOpenDialog(SourceForm As Form, Filter As String, Title As String, InitDir As String) As String
Dim A As Long
SourceForm.Enabled = False 'Let's start
GenerateRandomCaption 'Make an random caption
GetTitleBarHeight 'Calculates the height of the caption bar from registry.
If Filter = vbNullString Then 'if empty then set default
Filter = "All Files|*.*|"
End If
If Title = vbNullString Then 'if empty then set default
Title = GetCaption(Cap_Open_Window)
End If
'Formats the filter
If Right$(Filter, 1) = "|" Then Filter = Filter + "|"
For A = 1 To Len(Filter)
If Mid$(Filter, A, 1) = "|" Then Mid$(Filter, A, 1) = Chr$(0)
Next
'Put Variabels into memmory
Use_Filters = Filter
Use_InitDir = InitDir
Use_Caption = Title
On Error Resume Next 'Shometimes next gives strange errors while unloading
FrmOpen.Show 1
ShowExtendedOpenDialog = DialogRetData 'Function data set
SourceForm.Enabled = True 'Ok, we are ready
End Function
Sub Main()
'
' Example use of function
'
Dim Retval As String
MsgBox "This is a litte start of getting a open-file dialog into your interface." & Chr(10) & "It shure is not the right way, but i don't know to do it different... So if you know, please tell me!" & Chr(10) & Chr(10) & "Buggs: (Known)" & Chr(10) & "- User keyboard imput does not work correct." & Chr(10) & "- Screen flashes a little" & Chr(10) & Chr(10) & "Help wanted:" & Chr(10) & "- Getting the EXACT location en caption(Language depended) of the open en close button." & Chr(10) & "- The keyboard problem fix" & Chr(10) & Chr(10) & "You are free to use this code when you display my name (and what I made) in the aboutbox of your application." & Chr(10) & Chr(10) & "Please email your updates to 'Y2KFIXX@HOTMAIL.COM'", vbInformation
Retval = ShowExtendedOpenDialog(Form1, "All Files|*.*|", "", "C:\")
If Retval = vbNullString Then
MsgBox "User pressed cancel", vbInformation
ElseIf Left(Retval, 2) = "::" Then ''Use the double dot for templates!, this file can not exist
MsgBox "User choose an Example " & Retval, vbInformation
Else
MsgBox "User choose the file: " & Retval, vbInformation
End If
Unload Form1
End Sub
Function GetRescentFiles(Filename As String, Caption As String, Index As Integer) As Long
Dim i As Long
Dim TmpString As String
If Index = 0 Then
Do
i = i + 1
Loop Until GetStringValue(RegKey, "Filename" & i) = vbNullString